FROM gradle:8.11.1-jdk17-jammy AS tools
# 设置工作目录
WORKDIR /app

COPY cicd/apache-maven-3.9.10-bin.tar.gz .
# 下载并解压Maven
RUN tar -xzf apache-maven-3.9.10-bin.tar.gz \
    && mv apache-maven-3.9.10 maven \
    && rm apache-maven-3.9.10-bin.tar.gz


FROM gradle:8.11.1-jdk17-jammy AS builder

# 设置工作目录
WORKDIR /app

COPY --from=tools /app/maven /app/maven

ENV MAVEN_HOME=/app/maven
ENV PATH=${PATH}:${MAVEN_HOME}/bin

#COPY cicd/settings.xml ${MAVEN_HOME}/conf/

COPY . .

RUN ls -l /app

# 编译项目
RUN gradle :langchain4j:build -x test --stacktrace

RUN echo "🎉 编 🎉 译 🎉 成 🎉 功 🎉"

# 生产环境镜像（分离构建与运行层）
FROM eclipse-temurin:17-jre-alpine as production-stage
WORKDIR /app
COPY --from=builder /app/langchain4j/build/libs/*.jar /app/app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]